package com.service.admin.base.controller;

import com.service.admin.base.controller.req.SysFILConfigPageReq;
import com.service.admin.base.controller.req.SysFILQutoPerRewardReq;
import com.service.admin.base.service.SysFilConfigService;
import com.service.admin.framework.log.RequestLog;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.PageResponse;
import com.service.dao.model.SysFilConfig;
import com.service.utility.common.UUIDUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController()
@Api(tags = "FIL配置相关")
@RequestMapping("fil-pool")
public class SysFilConfigController extends BaseController {

	@Autowired
	private SysFilConfigService filConfigService;

	@ApiOperation("配置信息列表")
	@RequestLog("配置信息列表")
	@PostMapping("list")
	public PageResponse<SysFilConfig> list(@ApiParam @RequestBody SysFILConfigPageReq req){
		String uuid = UUIDUtil.randomUUID();
		log.info("请求开始 Msg: 请求参数：{}，UUID:{}", req, uuid);
		log.info("请求结束： UUID:{}", uuid);
		return successQueryPageResponse(filConfigService.pageFILConfig(req));
	}

	@ApiOperation("新增配置记录")
	@RequestLog("新增配置记录")
	@PostMapping("create")
	public BaseResponse create(@ApiParam @RequestBody SysFilConfig config){
		String uuid = UUIDUtil.randomUUID();
		log.info("请求开始 Msg: 请求参数：{}，UUID:{}", config, uuid);
		filConfigService.save(config);
		log.info("请求结束： UUID:{}", uuid);
		return successSaveBaseResponse();
	}

	@ApiOperation("修改配置记录")
	@RequestLog("修改配置记录")
	@PostMapping("modify")
	public BaseResponse modify(@ApiParam @RequestBody SysFilConfig config){
		String uuid = UUIDUtil.randomUUID();
		log.info("请求开始 Msg: 请求参数：{}，UUID:{}", config, uuid);
		filConfigService.updateById(config);
		log.info("请求结束： UUID:{}", uuid);
		return successUpdateBaseResponse();
	}

	@ApiOperation("获取FIL产出配置")
	@RequestLog("获取FIL产出配置")
	@GetMapping("initPerReward")
	public BaseResponse initPerReward(){
		return successBaseResponse(filConfigService.initPerReward().replace(" FIL/TiB",""));
	}

	@ApiOperation("修改FIL产出配置")
	@RequestLog("修改FIL产出配置")
	@PostMapping("perReward")
	public BaseResponse perReward(@ApiParam @RequestBody SysFILQutoPerRewardReq sysFILQutoPerRewardReq){
		String uuid = UUIDUtil.randomUUID();
		log.info("请求开始 Msg: 请求参数：{}，UUID:{}", sysFILQutoPerRewardReq, uuid);
		int rst = filConfigService.modifyFilQutoPerReward(sysFILQutoPerRewardReq);
		log.info("请求结束： UUID:{}", uuid);
		return successUpdateBaseResponse();
	}
}
